package com.Studen.controller;

import com.Studen.bean.User;
import com.Studen.servlet.DDLServlet;
import com.Studen.servlet.DDLServletMpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

@WebServlet("/insert")
public class InsertController extends HttpServlet {
    @Override
    protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        /**
         * 获取前台传过来的数据： 要添加学生的姓名、密码、分数等信息
         * 把这些数据封装在对象中、进行加入到数据库中
         *      将基本信息封装在user对象中 成绩封装在数组中
         *      将数据传到servlet层 在将数据从servlet中取出来用来可视化
         * **/
        //设置字符 防止乱码
        request.setCharacterEncoding("UTF-8");
        int son= Integer.parseInt(request.getParameter("son"));
        String name=request.getParameter("name");
        String pwd = request.getParameter("pwd");
        int sex = Integer.parseInt(request.getParameter("sex"));
        int java = Integer.parseInt(request.getParameter("java"));//Java这门课的成绩
        int python = Integer.parseInt(request.getParameter("Python"));
        int server = Integer.parseInt(request.getParameter("sjk"));
        int jsj = Integer.parseInt(request.getParameter("jsj"));
        User user = new User();
        user.setU_id(son);
        user.setU_name(name);
        user.setU_pwd(pwd);
        user.setU_sex(sex);

        int []a= {java,python,server,jsj};

        DDLServletMpl l = new DDLServletMpl();
        List<User>u =l.InsertServlet(user,a);
        //把前台传过来老师的id用来获取老师的相关信息

        request.setAttribute("user",u);
        request.getRequestDispatcher("main.jsp").forward(request,response);
    }
}

